package c2.cross.business.ladder.record;

import c2.cross.business.ladder.common.LadderPVPRecord;
import cate.game.pvp.ladder.common.LadderReport;
import cate.game.pvp.ladder.common.LadderReportQuery;
import cate.game.pvp.ladder.common.LadderReportResult;

import java.util.ArrayList;
import java.util.List;

public class LadderRecordDo {

    public void exe(LadderRecordModule recordMod, LadderReportQuery query) {
        LadderReport report = query.report;
        LadderPVPRecord pvpRecord = new LadderPVPRecord();
        pvpRecord.recordTime = report.recordTime;
        pvpRecord.rankA = report.rankA;
        pvpRecord.rankB = report.rankB;
        pvpRecord.replayUid = report.replayUid;
        pvpRecord.snapshotA = report.snapshotA;
        pvpRecord.snapshotB = report.snapshotB;
        pvpRecord.winner = report.winner;
        recordMod.addRecord(pvpRecord);
    }

    public LadderReportResult getList(LadderRecordModule ladderRecordModule, Integer limit) {
        List<LadderPVPRecord> reports = ladderRecordModule.getRecords();
        List<LadderReport> masterReports = new ArrayList<>();
        LadderReportResult result = new LadderReportResult();
        for (LadderPVPRecord report : reports){
            LadderReport record = new LadderReport();
            record.recordTime = report.recordTime;
            record.rankA = report.rankA;
            record.rankB = report.rankB;
            record.replayUid = report.replayUid;
            record.snapshotA = report.snapshotA;
            record.snapshotB = report.snapshotB;
            record.winner = report.winner;
            masterReports.add(record);
        }
        result.reports = masterReports;
        result.success();
        return result;
    }
}
